<?php

class Application_Model_RentCategory
    extends Application_Model_ModelAbstract
    implements Application_Model_ListElement
{
    public $category_id;
    public $category_title;
    public $category_icon;
    public $category_desc;
    public $category_4pu;
    public $category_gallery;

    /**
     * @param mixed $category_gallery
     */
    public function setCategoryGallery($category_gallery)
    {
        $this->category_gallery = $category_gallery;
    }

    /**
     * @return mixed
     */
    public function getCategoryGallery()
    {
        return $this->category_gallery;
    }

    /**
     * @param mixed $category_desc
     */
    public function setCategoryDesc($category_desc)
    {
        $this->category_desc = $category_desc;
    }

    /**
     * @return mixed
     */
    public function getCategoryDesc()
    {
        return $this->category_desc;
    }

    /**
     * @param mixed $category_icon
     */
    public function setCategoryIcon($category_icon)
    {
        $this->category_icon = $category_icon;
    }

    /**
     * @return mixed
     */
    public function getCategoryIcon()
    {
        return $this->category_icon;
    }

    /**
     * @param mixed $category_id
     */
    public function setCategoryId($category_id)
    {
        $this->category_id = $category_id;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->category_id;
    }

    /**
     * @param mixed $category_title
     */
    public function setCategoryTitle($category_title)
    {
        $this->category_title = $category_title;
    }

    /**
     * @return mixed
     */
    public function getCategoryTitle()
    {
        return $this->category_title;
    }

    public function getUrl()
    {
        return '/rent/' . $this->_get4PU();
    }

    public function _get4PU()
    {
        return $this->category_4pu;
    }

    public function getCategory4pu()
    {
        return $this->category_4pu;
    }

    public function getTitle()
    {
        return $this->getCategoryTitle();
    }

    public function getDesc($withPhotos = false)
    {
        return $withPhotos ? $this->getCategoryDesc() . $this->renderAlbum() : $this->getCategoryDesc();
    }

    public function getIconUrl()
    {
        return '/i/rentcat/' . $this->getCategoryIcon();
    }

    /**
     * @param mixed $category_4pu
     */
    public function setCategory4pu($category_4pu)
    {
        $this->category_4pu = $category_4pu;
    }

    /**
     *
     * @return Application_Model_GalleryAlbums|null
     */
    public function getAlbum()
    {
        if (!$this->getCategoryGallery()) {
            return null;
        }

        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_Gallery(), new Application_Model_GalleryAlbums());
        return $mapper->getById($this->getCategoryGallery());
    }

    /**
     *
     * @return Application_Model_Photo[]
     */
    public function getPhotos()
    {
        if (!$this->getCategoryGallery()) {
            return array();
        }

        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_Gallery(), new Application_Model_Photo());
        return $mapper->getCollection(array('album_id' => $this->getCategoryGallery()), 'photo_id DESC', array('count' => 3, 'start' => 0));
    }

    public function renderAlbum()
    {
        if (!$this->getCategoryGallery()) {
            return '';
        }

        $view = new Zend_View();
        $view->setScriptPath(APPLICATION_PATH . '/views/scripts/');
        $view->photos = $this->getPhotos();
        return $view->render('catalog/photos.phtml');
    }
}